﻿import mx.utils.Delegate;

import com.mixmedia.motion.MotionTween;
/**
 * @author colin
 */
class gui.WallPaper extends MovieClip {
	private static var depth:Number =0;
	private var mcBG:MovieClip;
	private var mcSelect:MovieClip;
	private var mcShadow:MovieClip;
	
	private var mt:MotionTween;
	private var mtShadow : MotionTween;
	private var mtBtn : MotionTween;

	private var mcHitArea : Button;

	private var id : String;
	private var outIID:Number;

	public function WallPaper(){
		id = _name.split("_")[1];
		mcBG.gotoAndStop(id);
		mt = new MotionTween(mcBG,{dur:10});
		mtBtn = new MotionTween(mcSelect); 
		mtShadow = new MotionTween(mcShadow);
		
		mcHitArea.onRollOver = Delegate.create(this,over);
		mcHitArea.onRollOut = Delegate.create(this,out);

		mcSelect._visible = false;
		mcSelect._alpha = 0;
	}
	
	public function over(){
		this.swapDepths(depth++);
		mtBtn.startTween({a:100});
		mtShadow.startTween({a:100,dur:25});
		mt.startTween({xs:120,ys:120});
	}

	public function out(){
		clearInterval(outIID);
		outIID = setInterval(Delegate.create(this,delayOut),250);
	}

	private function clearOut(){
		clearInterval(outIID);
	}
	
	private function delayOut(){
		clearInterval(outIID);
		mtBtn.startTween({a:0});
		mtShadow.startTween({a:0,dur:5});
		mt.startTween({xs:100,ys:100});	
	}
	
	public function download(arg:Number){
		getURL('wallpaper'+id+"_"+arg+'.zip');
	}
}